//
//  HMHomeViewController.m
//  OC新浪微博
//
//  Created by wyman on 16/4/10.
//  Copyright © 2016年 wyman. All rights reserved.
//

#import "HMHomeViewController.h"
#import "UIButton+HMTabarButton.h"
#import "HMHomeBtn.h"
#import "HMUserAccountModel.h"
#import "HMStatusModel.h"
#import "HMStatu.h"
#import "HMStatusCell.h"
@interface HMHomeViewController ()
@property (nonatomic, strong) NSArray *status;
@end

@implementation HMHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    BOOL islogin = ![HMUserAccountModel sharedInstance].userLogin;
    
    if(islogin){
        return;
    }

    //设置预估行号
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 200;
    [self.tableView registerClass:[HMStatusCell class] forCellReuseIdentifier:@"benchi"];
    //添加按钮
//    [self preTabar];
    
    UIButton *btn = [HMHomeBtn setTitleBtn:    [HMUserAccountModel sharedInstance].userAccount.screen_name
];
    
    [btn addTarget:self action:@selector(didClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = btn;
    
    [[HMStatusModel sharedInstance] loadStatuswithblock:^(NSArray *status, NSError *error) {
        if (error!=nil) {
            HMLog(@"加载微博信息出错");
            return;
        }
        
        self.status = status;
        [self.tableView reloadData];
    }];
    
    
}

-(void)didClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    
    [UIView animateWithDuration:0.25 animations:^{
        btn.selected == YES ? (btn.imageView.transform = CGAffineTransformMakeRotation(M_PI)) : (btn.imageView.transform = CGAffineTransformIdentity);
    }];


}
-(void)preTabar
{
//添加按钮
    UIBarButtonItem *button = [[UIBarButtonItem alloc]init];

    self.navigationItem.leftBarButtonItem = button;


}



-(void)registClicked
{


}
-(void)saosao
{
    NSLog(@"扫一扫");

}

/**
 *  代理方法
 */

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.status.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HMStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:@"benchi" forIndexPath:indexPath];
    HMStatu *statu = self.status[indexPath.row];
    
    cell.status = statu;
    
    return cell;
}

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    return NO;

}
@end
